package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.HandleDatailMapper;
import com.fc.test.model.auto.HandleDatail;
import com.fc.test.model.auto.HandleDatailExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 赋权要素清单 HandleDatailService
 * @Title: HandleDatailService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 1345625601@qq.com
 * @date 2020-09-11 22:08:34  
 **/
@Service
public class HandleDatailService implements BaseService<HandleDatail, HandleDatailExample>{
	@Autowired
	private HandleDatailMapper handleDatailMapper;
	
      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<HandleDatail> list(Tablepar tablepar,String searchText){
	        HandleDatailExample testExample=new HandleDatailExample();
	        testExample.setOrderByClause("id ASC");
	        if(StrUtil.isNotEmpty(searchText)){
	        	testExample.createCriteria().andAuthNameLike("%"+searchText+"%");
	        }
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<HandleDatail> list= handleDatailMapper.selectByExample(testExample);
	        PageInfo<HandleDatail> pageInfo = new PageInfo<HandleDatail>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			HandleDatailExample example=new HandleDatailExample();
			example.createCriteria().andIdIn(stringB);
			return handleDatailMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public HandleDatail selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return handleDatailMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(HandleDatail record) {
		return handleDatailMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(HandleDatail record) {
				
		record.setId(null);
		
				
		return handleDatailMapper.insertSelective(record);
	}

	/**
	 * 添加
	 */
	public int insert(HandleDatail record) {
		return handleDatailMapper.insertSelective(record);
	}
	
	@Override
	public int updateByExampleSelective(HandleDatail record, HandleDatailExample example) {
		
		return handleDatailMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(HandleDatail record, HandleDatailExample example) {
		
		return handleDatailMapper.updateByExample(record, example);
	}

	@Override
	public List<HandleDatail> selectByExample(HandleDatailExample example) {
		
		return handleDatailMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(HandleDatailExample example) {
		
		return handleDatailMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(HandleDatailExample example) {
		
		return handleDatailMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param handleDatail
	 * @return
	 */
	public int checkNameUnique(HandleDatail handleDatail){
		HandleDatailExample example=new HandleDatailExample();
		example.createCriteria().andAuthNameEqualTo(handleDatail.getAuthName());
		List<HandleDatail> list=handleDatailMapper.selectByExample(example);
		return list.size();
	}


    public void batchInsert(List<HandleDatail> list) {

		handleDatailMapper.batchInsert(list);
    }

	public List<HandleDatail> queryListByIds(List<Integer> ids) {
		return handleDatailMapper.queryListByIds(ids);

	}

	public void updateBatch(List<HandleDatail> list) {
		handleDatailMapper.updateBatch(list);
	}
}
